package com.ctshk.task.worker.processors;

import com.ctshk.common.dto.Result;
import com.ctshk.rpc.season.service.ISeasonFixedProductService;
import com.github.kfcfans.powerjob.worker.core.processor.ProcessResult;
import com.github.kfcfans.powerjob.worker.core.processor.TaskContext;
import com.github.kfcfans.powerjob.worker.core.processor.sdk.BasicProcessor;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Component;

/**
 * <p>
 * 定时刷新套票数据到ES
 * </p>
 *
 * @author Eric
 * @date 2021/5/25
 */
@Slf4j
@Component
public class SeasonCacheProcessor implements BasicProcessor {

    @DubboReference
    private ISeasonFixedProductService seasonFixedProductService;

    @Override
    public ProcessResult process(TaskContext context) throws Exception {
        log.info("固定套票线上缓存更新开始");
        try {
            Result result = seasonFixedProductService.searchInit(null);
            if (!result.isSuccess()) {
                log.error("固定套票线上缓存更新失败");
            } else {
                log.info("固定套票线上缓存更新成功");
            }
        } catch (Exception e) {
            log.error("固定套票线上缓存更新异常", e);
        }
        // 根据控制台参数判断是否成功
        boolean success = !"failed".equals(context.getJobParams());
        log.info("OrderEsProcessor SeasonCacheProcessor finished process,success: .", success);
        return new ProcessResult(success, context + ": " + success);
    }
}
